﻿package mortal.game.view.shop
{
    import Message.Public.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;

    public class BuyAdvanceOpenGiftPart extends GSprite
    {
        private var _itemData:ItemData;
        private var _shopItem:BaseItem;
        private var _propName:GTextFiled;
        private var _disCountTxt:GTextFiled;
        private var _oldPrice:GTextFiled;
        private var _price:GTextFiled;
        private var _leftNum:GTextFiled;
        private var _buyBtn:GLoadingButton;
        private var _numericStepper:GNumericStepper;
        private var _priceIcon1:GBitmap;
        private var _priceIcon2:GBitmap;

        public function BuyAdvanceOpenGiftPart()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._shopItem = UICompomentPool.getUICompoment(BaseItem);
            this._shopItem.x = 11;
            this._shopItem.y = 33;
            this._shopItem.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this.addChild(this._shopItem);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.size = 15;
            _loc_1.bold = true;
            this._propName = UIFactory.gTextField("", 11, 4, 235, 25, this, _loc_1, true);
            _loc_1.size = 12;
            _loc_1.bold = false;
            this._oldPrice = UIFactory.gTextField("", 109, 32, 140, 20, this, GlobalStyle.textFormatlan);
            this._price = UIFactory.gTextField("", 109, 56, 140, 20, this, _loc_1);
            _loc_1.align = TextFormatAlign.RIGHT;
            this._numericStepper = UIFactory.gNumericStepper(91, 82, 50, 20, this, 99, 1, "NumericStepper", _loc_1);
            this._numericStepper.configEventListener(Event.CHANGE, this.updateNum);
            this._numericStepper.value = 1;
            _loc_1 = GlobalStyle.textFormatHuang2;
            _loc_1.size = 17;
            _loc_1.bold = true;
            this._disCountTxt = UIFactory.gTextField("", 160, 2, 80, 25, this, _loc_1);
            _loc_1.align = TextFormatAlign.CENTER;
            _loc_1.size = 12;
            this._leftNum = UIFactory.gTextField("", 5, 113, 230, 25, this, _loc_1);
            this._buyBtn = UIFactory.gLoadingButton(ResFileConst.ShopMallBuyBtn, 175, 81, 51, 24, this);
            this._buyBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._priceIcon1 = UIFactory.gBitmap("", 200, 32, this);
            this._priceIcon2 = UIFactory.gBitmap("", 200, 56, this);
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.deleteLine, 167, 39, this));
            NetDispatcher.addCmdListener(ServerCommand.MoneyUpdate, this.updateNum);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.MoneyUpdate, this.updateNum);
            this._shopItem.dispose(param1);
            this._shopItem = null;
            this._propName.dispose(param1);
            this._propName = null;
            this._buyBtn.dispose(param1);
            this._buyBtn = null;
            this._priceIcon1.dispose(param1);
            this._priceIcon1 = null;
            this._priceIcon2.dispose(param1);
            this._priceIcon2 = null;
            this._disCountTxt.dispose(param1);
            this._disCountTxt = null;
            this._oldPrice.dispose(param1);
            this._oldPrice = null;
            this._price.dispose(param1);
            this._price = null;
            this._numericStepper.dispose(param1);
            this._numericStepper = null;
            this._leftNum.dispose(param1);
            this._leftNum = null;
            this._itemData = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function updateNum(param1:Object = null) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:GTextFormat = null;
            if (this._itemData)
            {
                _loc_2 = this._itemData.itemInfo.effect * this._numericStepper.value;
                _loc_3 = this._itemData.itemInfo.effectEx * this._numericStepper.value;
                this._oldPrice.text = Language.getString(35528) + _loc_3;
                if (Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitGold, _loc_2, null, false))
                {
                    _loc_4 = GlobalStyle.textFormatBai;
                }
                else
                {
                    _loc_4 = GlobalStyle.textFormatHong;
                }
                this._price.defaultTextFormat = _loc_4;
                this._price.text = Language.getString(35529) + _loc_2;
            }
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            var money:int;
            var enterAlert:Function;
            var e:* = event;
            enterAlert = function () : void
            {
                if (Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitGold, money))
                {
                    GameProxy.packProxy.useItem(_itemData.serverData.uid, _itemData.itemCode, _numericStepper.value);
                }
                else
                {
                    MsgManager.showRollTipsMsg(Language.getString(71273), MsgRollTipsType.msgRollTips3);
                }
                return;
            }// end function
            ;
            money = this._itemData.itemInfo.effect * this._numericStepper.value;
            var str:* = Language.getStringByParam(35534, money, this._itemData.itemInfo.name);
            TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.MulSelectWin, enterAlert, str, null, Alert.OK | Alert.CANCEL);
            return;
        }// end function

        public function buyItemHandler() : void
        {
            if (!Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitGold, this._itemData.itemInfo.effect))
            {
                MsgManager.showRollTipsMsg(Language.getString(35199), MsgRollTipsType.msgRollTips3);
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopBuyItemFail, null));
                return;
            }
            GameProxy.packProxy.useItem(this._itemData.serverData.uid, this._itemData.itemCode, this._numericStepper.value);
            return;
        }// end function

        public function set data(param1:ItemData) : void
        {
            this._itemData = param1;
            this._shopItem.itemData = this._itemData;
            this._propName.htmlText = ItemsUtil.getItemName(this._itemData);
            var _loc_2:* = this._itemData.itemInfo.effect / this._itemData.itemInfo.effectEx * 10;
            this._disCountTxt.text = "[ " + _loc_2.toString().slice(0, 3) + Language.getString(35530);
            this._priceIcon1.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(EPriceUnit._EPriceUnitGold));
            this._priceIcon2.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(EPriceUnit._EPriceUnitGold));
            this._oldPrice.text = Language.getString(35528) + this._itemData.itemInfo.effectEx;
            this._price.text = Language.getString(35529) + this._itemData.itemInfo.effect;
            if (Global.isDebugModle || ItemsUtil.isCanBulkUse(param1))
            {
                this._numericStepper.maximum = this._itemData.serverData.itemAmount;
            }
            else
            {
                this._numericStepper.maximum = 1;
            }
            this.updateNum();
            return;
        }// end function

    }
}
